<template>
  <el-container style="height: 100%">
    <div v-show="!show_main && !hidden_menu">
      <left></left>
    </div>
    <el-container>
      <el-header style="padding: 0">
        <div v-show="!show_main">
          <top></top>
        </div>
        <tabs></tabs>
      </el-header>
      <el-main style="background: #f0f2f5; height: 100%; overflow: hidden">
        <!-- <router-view></router-view> -->
        <transition :name="transitionName" mode="out-in">
          <router-view class="router-view" v-slot="{ Component }">
            <component :is="Component" />
          </router-view>
        </transition>
      </el-main>
    </el-container>
    <div class="setup" v-if="show_main">
      <el-tooltip content="工程配置" placement="bottom">
        <svgBtn
          style="
            font-size: 20px !important;
            padding: 5px;
            margin: 0 5px;
            border-radius: 3px;
            height: 20px;
            line-height: 20px;
          "
          :style="{
            backgroundColor: svg_color == '#3580eb' ? '#ECF4FF' : '',
          }"
          :color="svg_color"
          @mouseenter="svg_color = '#3580eb'"
          @mouseleave="svg_color = '#45474A'"
          icon="setup"
          @click="show_setup_box = true"
        ></svgBtn>
      </el-tooltip>
    </div>
  </el-container>
  <el-drawer
    v-model="show_setup_box"
    direction="rtl"
    size="30%"
    :close-on-click-modal="false"
  >
    <template #title>
      <h4>项目配置</h4>
    </template>

    <template #default>
      <set_up @close="show_setup_box = false" :show_main="!show_main"></set_up>
    </template>
  </el-drawer>
  <div class="lock_box" v-if="lock_box">
    <div v-if="!show_lock_input">
      <div style="font-size: 200px">{{ time_list[0] }}</div>
      <div class="fs_30" style="margin-bottom: 80px">
        {{ time_list[1] }} {{ time_list[2] }}
      </div>
      <div class="lock_icon" @click="show_lock_input = true">
        <svgBtn icon="suoding" style="font-size: 40px"></svgBtn>
      </div>
      <div class="m_top15">点击解锁</div>
    </div>
    <div
      v-else
      style="
        width: 100%;
        height: 100%;
        background: rgba(9, 28, 54, 0.26);
        backdrop-filter: blur(3px);
      "
    >
      <div style="font-size: 40px">{{ time_list[0] }}</div>
      <div class="fs_20" style="margin-bottom: 80px">
        {{ time_list[1] }} {{ time_list[2] }}
      </div>
      <div class="tc m_bottom30">
        <img
          :src="store.state.user_info.headPic"
          style="
            width: 96px;
            height: 96px;
            border-radius: 50%;
            border: 2px solid #c7d2e2;
          "
          alt=""
        />
        <div class="m_top10">{{ store.state.user_info.username }}</div>
      </div>
      <el-input
        placeholder="请输入密码"
        style="border: 1px solid #fff; width: 320px"
        v-model="lock_keyword"
        @keyup.enter="close_lock"
      ></el-input>
      <div class="flex_js" style="width: 320px; margin: 10px auto 30px auto">
        <span @click="show_lock_input = false" style="cursor: pointer"
          >返回</span
        >
        <span @click="close" style="cursor: pointer">返回登录</span>
      </div>
      <el-button
        type="primary"
        style="width: 320px; height: 48px"
        @click="close_lock"
        >进入系统</el-button
      >
    </div>
  </div>
</template>

<script lang="ts" setup>
import { dictData } from '@/utils/utils'
import left from './container/left.vue'
import top from './container/top.vue'
import tabs from './container/tabs.vue'
import Eventbus from '@/utils/EventBus'
import svgBtn from '@/components/svg_button.vue'
import set_up from '@/view/components/setup.vue'
import { ref, onMounted, computed, onUnmounted } from 'vue'
import { useRouter } from 'vue-router'
import { useStore } from 'vuex'
import axios from '@/service/HttpRequest'
import serviceApi from '@/service/api'
import { getCookie, setCookie } from '@/utils/cookie'
import { ElMessage } from 'element-plus'
const transitionName = ref('slide-left')
const router = useRouter()
const svg_color = ref('#45474A')
const show_main = computed(() => {
  console.log(store.state.is_all_page)
  return store.state.is_all_page
})
const store = useStore()
const hidden_menu = computed(() => {
  return store.state.is_top_menu
})
const show_setup_box = ref(false)
const lock_box = ref(false)
const time_list = ref([])
const show_lock_input = ref(false)
const lock_keyword = ref('') // 锁屏密码
const currentRoute = ref()
onMounted(() => {
  currentRoute.value =
    router.currentRoute.value.name == 'home'
      ? 'index'
      : router.currentRoute.value.name
  console.log(currentRoute.value)
  Eventbus.emit('change_default_active', '/' + currentRoute.value)
  router.push({ name: currentRoute.value })
  var weekday = [
    '星期日',
    '星期一',
    '星期二',
    '星期三',
    '星期四',
    '星期五',
    '星期六',
  ]
  Eventbus.on('lock', () => {
    var d = new Date()
    time_list.value[0] =
      d.getHours() +
      ':' +
      (d.getMinutes() > 9 ? d.getMinutes() : '0' + d.getMinutes())
    time_list.value[1] = d.getMonth() + 1 + '月' + d.getDate() + '日'
    time_list.value[2] = weekday[d.getDay()]
    lock_box.value = true
  })
  console.log(time_list.value)
  if (getCookie('lock_keyword')) {
    lock_box.value = true
  }
  dictData('1541665967619182594').then((res) => {
    ;(res as any).forEach((item) => {
      item.label = item.dictValue
      item.value = item.dictCode
    })
    store.commit('set_product_list', res as any)
  }) // 获取字典值  // 产品列表
  // 获取平台所有用户
  get_member_list()
  // 获取平台所有企业
  get_enterprise_list()
})
onUnmounted(() => {
  Eventbus.off('lock')
})
const get_member_list = () => {
  axios
    .request({
      url: serviceApi.user_list,
      method: 'post',
      data: { current: 1, pageSize: 200 },
    })
    .then((res) => {
      res.data.content.forEach((item) => {
        item.label = item.username
        item.value = item.id
      })
      store.commit('set_user_list', res.data.content)
    })
}
const get_enterprise_list = () => {
  axios
    .request({
      url: serviceApi.all_enterprise_list,
      method: 'post',
    })
    .then((res) => {
      res.data.forEach((item) => {
        item.label = item.name
        item.value = item.id
        item.disabled = false
      })
      store.commit('set_enterprise_list', res.data)
    })
    .catch((err) => {
      ElMessage.error(err)
    })
}
const close_lock = () => {
  if (lock_keyword.value != getCookie('lock_keyword')) {
    ElMessage.error('请输入正确的锁屏密码')
  } else {
    lock_keyword.value = ''
    show_lock_input.value = false
    lock_box.value = false
    setCookie('lock_keyword', '', -1)
  }
}
const close = () => {
  setCookie('bimai_admin_token', '', -1)
  setCookie('lock_keyword', '', -1)
  router.push({ name: '/' })
}
</script>

<style lang="scss" scoped>
:deep(.el-input) {
  --el-input-focus-border-color: '';
}
.slide-left-enter-from {
  transform: translateX(-20px);
  opacity: 0;
}

.slide-left-enter-to {
  transform: translateX(0px);
}

.slide-left-leave-from {
  transform: translateX(0);
}

.slide-left-leave-to {
  transform: translateX(20px);
  opacity: 0;
}

.slide-left-enter-active,
.slide-left-leave-active {
  transition: all 0.3s;
}
.lock_box {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1001;
  width: 100%;
  height: 100%;
  background-image: url(@/assets/img/lock_bg.png);
  background-size: 100% 100%;
  display: flex;
  justify-content: center;
  color: #fff;
  > div {
    padding-top: 150px;
    text-align: center;
  }
  :deep(.el-input) {
    --el-input-placeholder-color: #fff;
    color: #fff;
  }
  .lock_icon {
    width: 108px;
    height: 108px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.24);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
    cursor: pointer;
  }
  :deep(.el-input__inner) {
    color: #fff;
    background-color: rgba(128, 140, 158, 0.26);
  }
}
.setup {
  position: fixed;
  right: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  top: 50%;
  box-shadow: 0px 0px 5px 5px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.el-container {
  height: 100%;
  overflow: hidden;
}
</style>
